package com.junsi.ding.talk.util;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;

public class DingConfigUtil {
	private static Properties pro = null;
	private static final Log logger = LogFactory.getLog(DingConfigUtil.class);
	static {
		try {
			YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
			yamlFactory.setResources(new ClassPathResource("application.yml"));
			String profile = yamlFactory.getObject().getProperty("spring.profiles.active");

			yamlFactory = new YamlPropertiesFactoryBean();
			yamlFactory.setResources(new ClassPathResource("application-"+profile+".yml"));
			pro = yamlFactory.getObject();
		} catch (Exception e) {
			logger.error("DingConfigUtil加载属性配置文件出错。", e);
		}
	}

	/**
	 * 获取属性值
	 * @throws IOException
	 */
	public static String getAuthConfig(String key) {
		return pro.getProperty(key);
	}

	public static void main(String[] args) {
		System.out.println(DingConfigUtil.getAuthConfig("dingding.agentid"));
	}
}
